#ifndef NET_ACCEPTOR_H_
#define NET_ACCEPTOR_H_

#include "base/base.h"

namespace net {
class Poller;
struct Addr;
class Socket;
struct Event;
class TcpServer;

class Acceptor {
  public:
    Acceptor(Poller* poller, TcpServer* owner)
        : poller_(poller), owner_(owner) {
    }

    bool Listen(const Addr &addr_);
    bool EnableRead();

    Socket* Accept();

    TcpServer* Owner() const {
      return owner_;
    }

    static void HandleRead(int fd, void* arg, int event);

  private:
    Poller* poller_;
    TcpServer* owner_;

    scoped_ptr<Socket> accept_socket_;
    scoped_ptr<Event> ev_;

    DISALLOW_COPY_AND_ASSIGN(Acceptor);
};
}

#endif
